package com.ruoyi.system.controller;



import com.ruoyi.system.dto.Logg;
import com.ruoyi.system.dto.BusinessinTypeEnum;
import com.ruoyi.system.domain.RR;
import com.ruoyi.system.utils.PageinUtils;
import com.ruoyi.system.utils.SecurityUserUtil;
import com.ruoyi.system.utils.BaseinController;
import com.ruoyi.system.utils.TableinDataInfo;
import com.ruoyi.system.domain.SysHeaderFilter;
import com.ruoyi.system.service.ISysHeaderFilterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 用户默认头筛选Controller
 *
 * @author zsincere
 * @date 2023-09-16
 */
@RestController
@RequestMapping("/system/headerFilter")
public class SysHeaderFilterController extends BaseinController
{
    @Autowired
    private ISysHeaderFilterService sysHeaderFilterService;

    /**
     * 获取用户全部显隐列配置
     */
    @GetMapping("/defaultHeader")
    public RR getDefaultHeader(){
        String username = SecurityUserUtil.getUsername();
        Map<Object, Object> resultMap = sysHeaderFilterService.getDefaultHeader(username);
        return RR.ok().setData(resultMap);
    }

    /**
     * 保存用户当前页的显隐列配置
     */
    @PostMapping("/defaultHeader")
    public RR uploadDefaultHeader(@RequestParam("pageName") String pageName, @RequestBody(required = false) List<SysHeaderFilter> list){
        String username = SecurityUserUtil.getUsername();
        sysHeaderFilterService.uploadHeaderFilter(pageName, username, list);
        return RR.ok().setData(sysHeaderFilterService.getDefaultHeader(username));
    }

    /**
     * 查询用户默认头筛选列表
     */
    @PreAuthorize("hasAuthority('system:headerFilter:list')")
    @GetMapping("/list")
    public TableinDataInfo list(SysHeaderFilter sysHeaderFilter)
    {
        startPage();
        List<SysHeaderFilter> list = sysHeaderFilterService.selectSysHeaderFilterList(sysHeaderFilter);
        return getDataTable(list);
    }

    /**
     * 获取用户默认头筛选详细信息
     */
    @PreAuthorize("hasAuthority('system:headerFilter:query')")
    @GetMapping(value = "/{id}")
    public RR getInfo(@PathVariable("id") Long id)
    {
        return RR.ok().setData(sysHeaderFilterService.selectSysHeaderFilterById(id));
    }

    /**
     * 新增用户默认头筛选
     */
    @PreAuthorize("hasAuthority('system:headerFilter:add')")
    @Logg(title = "用户默认头筛选", businessType = BusinessinTypeEnum.INSERT)
    @PostMapping
    public RR add(@RequestBody SysHeaderFilter sysHeaderFilter)
    {
        return RR.ok().setData(sysHeaderFilterService.insertSysHeaderFilter(sysHeaderFilter));
    }

    /**
     * 修改用户默认头筛选
     */
    @PreAuthorize("hasAuthority('system:headerFilter:edit')")
    @Logg(title = "用户默认头筛选", businessType = BusinessinTypeEnum.UPDATE)
    @PutMapping
    public RR edit(@RequestBody SysHeaderFilter sysHeaderFilter)
    {
        return RR.ok().setData(sysHeaderFilterService.updateSysHeaderFilter(sysHeaderFilter));
    }

    /**
     * 删除用户默认头筛选
     */
    @PreAuthorize("hasAuthority('system:headerFilter:remove')")
    @Logg(title = "用户默认头筛选", businessType = BusinessinTypeEnum.DELETE)
    @DeleteMapping("/{ids}")
    public RR remove(@PathVariable Long[] ids)
    {
        return RR.ok().setData(sysHeaderFilterService.deleteSysHeaderFilterByIds(ids));
    }
}

